package cn.unknowpupil.service.system.impl;

import cn.unknowpupil.common.core.utils.StringUtils;
import cn.unknowpupil.domain.system.SysNotice;
import cn.unknowpupil.mapper.system.SysNoticeMapper;
import cn.unknowpupil.service.system.ISysNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created at 2020-11-03 by  w10g <br>
 * Initialize SysNotice  ... <br>
 *  通知公告表 核心业务处理实现类
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice>implements ISysNoticeService {


        /**
         *  新增
         * @param sysNotice {@link SysNotice}  通知公告表
         * @return {@link SysNotice}
         */
        @Override
        public  boolean create( SysNotice sysNotice ){
            return save(sysNotice);
        }

        /**
         *  详情
         * @param id {@code Long}   SysNotice ID
         * @return {@link SysNotice}
         */
        @Override
        public  SysNotice info(Long id){
            return getById(id);
        }

        /**
         *  删除
         * @param ids {@code Long}   ids
         * @return {@link SysNotice}
         */
        @Override
        public  boolean delete(Long[] ids){
            List<Long> collect = Stream.of(ids).collect(Collectors.toList());
            return removeByIds(collect);
        }


        /**
         *  修改
         * @param sysNotice {@link SysNotice}  通知公告表
         * @return {@link SysNotice}
         */
        @Override
        public  boolean update( SysNotice sysNotice ){
            return updateById(sysNotice);
        }


        /**
         * 分页
         * @param current {@code int} 页码
         * @param size {@code int} 笔数
         * @param sysNotice {@link SysNotice}
         * @return {@code IPage<SysNotice>}
         */
        @Override
        public IPage<SysNotice> page(int current, int size, SysNotice sysNotice){
            IPage<SysNotice> page = new Page<>(current, size);
            LambdaQueryWrapper<SysNotice> wrapper = new LambdaQueryWrapper<>();
           if(StringUtils.isNotBlank(sysNotice.getNoticeTitle())){
               wrapper.like(SysNotice::getNoticeTitle,sysNotice.getNoticeTitle());
           }
            if(StringUtils.isNotBlank(sysNotice.getNoticeType())){
                wrapper.eq(SysNotice::getNoticeType,sysNotice.getNoticeType());
            }
            if(StringUtils.isNotBlank(sysNotice.getCreateBy())){
                wrapper.like(SysNotice::getCreateBy,sysNotice.getCreateBy());

            }
            return super.page(page, wrapper);
        }

}
